﻿using AnesSystem.Models;
using AnesSystem.Services;
using AnesSystem.Util;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AnesSystem.ViewModels
{
    class ShichangCountCtrlViewModel:BaseViewModel<ShichangCountCtrlViewModel>
    {
        #region Variables
        private ObservableCollection<StatisticsPatientLinkModel> _disPatientLinkModelList = new ObservableCollection<StatisticsPatientLinkModel>();
        IEnumerable<PatientLinkModel> PatientLinkModels = new List<PatientLinkModel>();
        //入室-麻醉开始时间
        private List<string> _irt_mst=new List<string>();
        //麻醉开始时间-手术开始时间
        private List<string> _mst_ost = new List<string>();
        //手术开始时间-手术结束时间
        private List<string> _ost_oet = new List<string>();
        //开始时间
        protected DateTime _startDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1, 0, 0, 0);
        //结束时间
        protected DateTime _endDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 23, 59, 59);
        private ObservableCollection<MonthModel> monthMethodList = new ObservableCollection<MonthModel>();
        private MonthModel _selectedMonthMethod;
        #endregion
        //Status，InRoomTime入室时间入室时间，OutRoomTime出室时间，MazuiStartTime麻醉开始时间，MazuiEndTime麻醉结束时间，OperStartTime手术间时间，OperEndTime手术结束时间
        #region Constructor

        public ShichangCountCtrlViewModel()
        {
            CreateMonthMondelList();

        }
        #endregion

        #region Properties
        public ObservableCollection<StatisticsPatientLinkModel> DisPatientLinkModelList
        {
            get
            {
               
                return _disPatientLinkModelList;
            }

            set
            {
                _disPatientLinkModelList = value;
                RaisePropertyChanged("DisPatientLinkModelList");
            }
        }

        public DateTime StartDate
        {
            get
            {
                return _startDate;
            }

            set
            {
                _startDate = value;
                RaisePropertyChanged("StartDate");
            }
        }

        public DateTime EndDate
        {
            get
            {
                return _endDate;
            }

            set
            {
                _endDate = value;
                RaisePropertyChanged("EndDate");
            }
        }

        public ObservableCollection<MonthModel> MonthMethodList
        {
            get
            {
                return monthMethodList;
            }

            set
            {
                monthMethodList = value;
            }
        }

        public MonthModel SelectedMonthMethod
        {
            get
            {
                return _selectedMonthMethod;
            }

            set
            {
                _selectedMonthMethod = value;
                GetMonthStartDate();
                RaisePropertyChanged("SelectedMonthMethod");
            }
        }
        #endregion

        #region 依赖属性

        #endregion

        #region Event

        #endregion

        #region Private Methods
        private void CreateMonthMondelList()
        {
            MonthMethodList.Add(new MonthModel("", 0));
            string[] strArr = { "一月", "二月", "三月", "四月", "五月", "半年", "七月", "八月", "九月", "十月", "十一月", "一年" };
            for (int i = 0; i < strArr.Length; i++)
            {
                MonthMethodList.Add(new MonthModel("近" + strArr[i], i + 1));
            }
        }
        private void GetMonthStartDate()
        {

            EndDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 23, 59, 59);
            if (DateTime.Now.Month - SelectedMonthMethod.Code < 0)
            {
                StartDate = new DateTime(DateTime.Now.Year - 1, 13 + (DateTime.Now.Month - SelectedMonthMethod.Code), 1, 0, 0, 0);
            }
            else
            {
                StartDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month - SelectedMonthMethod.Code + 1, 1, 0, 0, 0);
            }
        }
        #endregion

        #region Public/Protected Methods
        public void Seach()
        {
            _disPatientLinkModelList.Clear();
            PatientLinkModels = PatientLinkService.Instance.GetBaseCount(StartDate, EndDate).OrderByDescending(O => O.Status.InRoomTime);
            foreach (var item in PatientLinkModels)
            {
                _disPatientLinkModelList.Add(item.ConversionPatientLink());
            }
        }


        public void Excel()
        {

            if (PatientLinkModels == null || PatientLinkModels.ToList().Count == 0)
            {
                MessageBoxCommon.ShowDialog("请先查询病人!", MessageBoxCommon.OK);
                return;
            }
            ExportToExcel excel = new ExportToExcel();
            excel.ExportParameterCommon("历史手术", PatientLinkModels.ToList());
        }
        #endregion

        #region EventHandlers

        #endregion
    }
}
